FUNCTION boxselector_manip::Init, $
    _REF_EXTRA=_extra

COMPILE_OPT idl2, HIDDEN

; Initialize the manipulator.
IF (~self->IDLitManipulator::Init( $
   NAME='Box Selector', $
   TYPES=['IDLPLOT'], $
   _EXTRA = _extra)) THEN $
      RETURN, 0

; Register the cursor of the manipulator.
self->boxselector_manip::DoRegisterCursor

; Indicate success if all has succeeded.
RETURN, 1
END

; ****************************************************************
; Configure the DoRegisterCursor method
; This method will create the cursor for the manipulator.
pro boxselector_manip::DoRegisterCursor

  compile_opt idl2, hidden

; Define the default cursor for this manipulation.

  strArray = [ $
        '..              ', $
        '.#.             ', $
        '.##.            ', $
        '.###.           ', $
        '.####.          ', $
        '.#####.         ', $
        '.######.        ', $
        '.#######.       ', $
        '.########.      ', $
        '.#########.     ', $
        '.##########.    ', $
        '......###...    ', $
        '     .###.      ', $
        '      .###.     ', $
        '      .###.     ', $
        '       ....     ']

; Register the new cursor with the tool.
  self->RegisterCursor, strArray, 'LUT', /DEFAULT
END


pro boxselector_manip::OnMouseDown, oWin, x, y, iButton, $
    KeyMods, nClicks
    self->IDLitManipulator::OnMouseDown, oWin, x, y, iButton, Keymods, nClicks
	self.ovis = (*self.pSelectionList)[0]
	self.startx = x
	self.starty = y

end

pro boxselector_manip::OnMouseUp, oWin, x, y, iButton
	self->IDLitManipulator::OnMouseUp, oWin, x, y, iButton
	print, self.ovis

	self.ovis->WindowToVis, self.startx, self.starty, dxs, dys
	self.ovis->WindowToVis, x, y, dxe, dye
	print, self.startx, self.starty
	print, x, y
	print, dxs, dys
	print, dxe, dye

	newpoints = (*((*(self.uvalue)).pdata3d))[*,extract_spatial_subset($
		*((*(self.uvalue)).pdata3d), $
		dxs[0] > dxe[0], dxs[0] < dxe[0], dys[0] > dye[0], dys[0] < dye[0])]
	iplot, /scatter, scale_isotropic=1, $
		newpoints
	*((*(self.uvalue)).pptr_return_here) = ptr_new(newpoints)
end


pro boxselector_manip__define
	compile_opt idl2, hidden

	void = {boxselector_manip, $
			inherits IDLitManipulator, $
			ovis: obj_new(), $
			startx:0L, starty:0L}

end